package com.zhuss.core.processor;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.core.area.DeleteAreaBo;
import com.zhuss.bean.vo.core.area.DetailAreaVo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.core.db.dao.ext.AreaDao;
import com.zhuss.core.db.entity.Area;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.OceanException;
import com.zhuss.util.JsonUtil;

/**
 * @description: 地域删除
 * @author: zhushanshuo
 * @create: Thu Apr 08 20:24:46 CST 2021
 **/
@Component("areaDelete")
public class AreaDelete extends AbstractProcessor<Object, DeleteAreaBo> implements Processor<Object, DeleteAreaBo> {

    @Autowired
    private AreaDao areaDao;
    
    @Autowired
	@Qualifier("areaRead")
	private AreaRead areaRead;
    
    
    /**
     * 校验
     */
	@Override
    public void check(DeleteAreaBo bo) throws OceanException {
		// TODO 删除 地域 校验， 请补充
    }
    
    /**
     * 操作方法
     */
    @Override
    public Object process(DeleteAreaBo param) throws OceanException {
    	Long areaId = param.getAreaId();
    	String name = ((DetailAreaVo) areaRead.detail(areaId)).getName();
    	
    	Area record = new Area();
    	record.setAreaId(areaId);
    	record.setDeleted(param.getDeleted());
    	
    	record.setModifierId(param.getConcurrentUserId());
    	record.setModifier(param.getConcurrentUserName());
    	record.setModifyTime(new Date());
    	areaDao.delete(record);
    	param.setName(name);
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Object log(DeleteAreaBo param) throws OceanException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.基础模块.key());
    	record.setAction(LogActionEnum.地域删除.key());
    	record.setTargetId(param.getAreaId());
    	record.setTargetName(param.getName());
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
